package com.baidu.dao.abstractclass;

import com.baidu.common.exception.WebException;
import com.baidu.common.util.PropertiesUtil;
import com.baidu.dao.interfaces.BaseDao;
import com.baidu.dao.util.JdbcUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @Author: BSS
 * @create: 2020/8/24/20:16
 */
public abstract class BaseAbstract<T> implements BaseDao<T> {
    public Connection connection = JdbcUtil.getConnection();

    protected BaseAbstract() throws WebException {
    }

    {
        PropertiesUtil.reload(JdbcUtil.PROFILE_SQL);
    }

    /**
     * 根据key获取配置文件的sql语句
     * @param key key
     * @return sql
     * @throws WebException 读取异常信息
     */
    public String getPropertiesString(String key) throws WebException {
        return PropertiesUtil.getString(key);
    }

    public void closeStatementAndResultSet(Statement statement, ResultSet resultSet) throws WebException {
        JdbcUtil.closeStatement(statement);
        JdbcUtil.closeResultSet(resultSet);
    }
}
